package com.k.mclock.activity

import android.os.Bundle
import android.view.WindowManager
import androidx.activity.enableEdgeToEdge
import androidx.appcompat.app.AppCompatActivity
import androidx.core.view.ViewCompat
import androidx.core.view.WindowInsetsCompat
import com.k.mclock.R
import com.k.mclock.view.FlipCountDownView
import com.k.mclock.view.FlipTextView

class MainActivity : AppCompatActivity() {

    private var counter = 60
    private lateinit var flipText: FlipTextView
    private lateinit var countdown: FlipCountDownView

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        enableEdgeToEdge()
        setContentView(R.layout.activity_main)
        ViewCompat.setOnApplyWindowInsetsListener(findViewById(R.id.main)) { v, insets ->
            val systemBars = insets.getInsets(WindowInsetsCompat.Type.systemBars())
            v.setPadding(systemBars.left, systemBars.top, systemBars.right, systemBars.bottom)
            insets
        }

        initView()

        window.addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON) // 屏幕常亮
    }

    private fun initView() {
        flipText = findViewById(R.id.flipText)
        countdown = findViewById(R.id.countdown)

        flipText.setOnClickListener {
            if (counter > 0) {
                counter--
                flipText.text = "$counter"
            }
        }
        flipText.text = "$counter"

        countdown.deadlineTime = System.currentTimeMillis() + 10 * 60 * 1000
    }
}